from selenium import webdriver
from selenium.webdriver.common.by import By
import time

class TestCase:
    def __init__(self):
        #初始化对象
        self.driver = webdriver.Chrome()

    def get_baidu(self):
        #请求百度
        self.driver.get('http://www.baidu.com')
        #搜索框输入内容
        time.sleep(2)
        self.driver.find_element(By.ID, 'kw').send_keys('天气预报')
        #点击百度一下
        time.sleep(2)
        self.driver.find_element(By.ID, 'su').click()

    def get_so(self):
        self.driver.get('http://www.so.com')
        time.sleep(2)
        self.driver.find_element(By.ID, 'input').send_keys('天气预报')
        time.sleep(2)
        self.driver.find_element(By.ID, 'input').click()


    # seconds
    def quit(self,seconds=2):
        time.sleep(seconds)
        self.driver.quit()


if __name__ == '__main__':
    case = TestCase()
    case.get_baidu()
    case.quit()


# from selenium import webdriver
# from selenium.webdriver.common.by import By
# driver = webdriver.Chrome()
# driver.get('http://www.baidu.com')
# kw = driver.find_element(By.ID, 'kw')
# kw.send_keys('天气预报')
# su = driver.find_element(By.ID, 'su')
# su.click()
# print(driver.title)
# if '天气预报' in driver.title:
#     print('ok')
# else:
#     print('no')
# driver.quit()

# from selenium import webdriver
# from selenium.webdriver.common.by import By
# driver = webdriver.Chrome()
# driver.get('http://www.baidu.com')
# kw = driver.find_element(By.ID, 'kw')
# kw.send_keys('天气预报')
# su = driver.find_element(By.ID, 'su')
# su.click()
# print(driver.title)
# if '天气预报' in driver.title:
#     print('ok')
# else:
#     print('no')
# driver.quit()

